package com.h.ioc.controller;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/proper")
@Controller
@ResponseBody
public class PropertiesController {

    @Value("${my.key}")
    private Integer myKey;

    @Value("${my.key2}")
    private boolean myKey2;

    @RequestMapping("/read")
    public String readValue() {
        return "读取的配置文件my.key = " + myKey + "读取的配置文件my.key2 = " + myKey2;
    }

    // 表示该方法在类实例化之后，立即执行
    @PostConstruct
    public void init() {
        System.out.println("读取的配置文件my.key = " + myKey);
        System.out.println("读取的配置文件my.key2 = " + myKey2);
    }
}
